/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package unc.pds.facets;

import com.sun.faces.util.CollectionsUtils.ConstMap;
import unc.pds.auth.IPDSSecurity;
import unc.pds.data.Consts;
import unc.pds.model.GroupRemote;
import unc.pds.model.UserRemote;

/**
 *
 * @author Mikhail
 */
public class MembersFacet implements Facet {
   public MembersFacet(GroupRemote group, IPDSSecurity security) {
        this.group = group;
        this.security = security;
    }
    GroupRemote group;
    IPDSSecurity security;
    public String draw() throws Exception {
        String result = "";
        UserRemote[] users = group.getMembers();
        result += "<h4>Пользователи:</h4>";
        for (int i=0; i<users.length; i++) {
            result += "<p><a href = \"index.jsp?id="+ users[i].getKey() +"&view=posts\">"+ users[i].getNickname() +"</a>";
            if (group.isModer(users[i].getKey())) {
                result += " - Модератор";
            }
            if (security.getPermission(group.getKey(), Consts.ATTR__GROUP_MEMBER, "delete")) {
                if (group.getOwner().getKey()!=users[i].getKey()) {
                    result += " <a href = \"group-processor.jsp?action=removemember&id="+ users[i].getKey() +"&gid="+group.getKey()+"\"><img src=\"img/decline.png\" alt=\"Удалить\"/></a>";
                } else {
                    result += " - Владелец";
                }
            }
            result += "</p>\n";
        }
        return result;
    }
    public boolean isSide() {
        return false;
    }
}
